

//
//  NEditInfoViewController.m
//  nncloud
//
//  Created by macfai on 2018/12/26.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NEditInfoViewController.h"
#import "NZhaopinCell.h"
#import "NMiaoshuCell.h"
#import "NEditDeleteView.h"

@interface NEditInfoViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,STPickerSingleDelegate,UITextViewDelegate>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@property(nonatomic,strong)NSArray *titleArray;
@property(nonatomic,strong)NSArray *infoArray;

@property (nonatomic,copy)NSString *selfIntroMsg;
@property (nonatomic,copy)NSString *content;


@property (nonatomic,strong)STPickerSingle *picker;

@end

@implementation NEditInfoViewController

//求职详情
#define cellIdentifier @"zhaopin"
#define miaoshuCell @"miaoshu"
#define SectionHeaderHeight  10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        //        _tableView.rowHeight = 115.f;
        _tableView.separatorStyle = 0;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NZhaopinCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        [_tableView registerNib:[UINib nibWithNibName:@"NMiaoshuCell" bundle:nil] forCellReuseIdentifier:miaoshuCell];
        _tableView.showsVerticalScrollIndicator = NO;
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    self.dataArray = [NSMutableArray array];
    [self.navigationItem setItemWithTitle:@"编辑信息" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    [self addNavgationRightButtonWithFrame:CGRectMake(0, 0, 40, 40) title:@"保存" Image:nil selectedIMG:nil tartget:self action:@selector(saveAction)];
    self.titleArray = @[@"性别",@"生日",@"婚姻状况",@"身高(单位:cm)",@"体重(单位:kg)",@"居住地",@"学历",@"毕业院校",@"专业",@"工作性质",@"工作经验",@"行业意向",@"职位意向",@"专业技能",@"期望薪资(单位:元)",@"求职状态",];
    //    self.infoArray = @[@"男",@"1990-9-8",@"已婚",@"175",@"160",@"北京",@"本科",@"北京大学",@"英语",@"民营",@"5年",@"行业意向",@"职位意向",@"高级开发",@"25",@"寻求机会",];
    [self.view addSubview:self.tableView];
}

- (void)setInfoArr:(NSArray *)infoArr{
    _infoArr = infoArr;
    self.infoArray = infoArr;
}

- (void)saveAction {
    

//    BOOL isRequestDifferent = YES;
    [NUserModel shareInstance].isDifferentRequest = YES;
    YYLog(@"保存");
    ///调用修改接口  这个接口是经过特殊改造的，后台设置了请求上传的数据格式
    NSDictionary *dic = @{@"resumeUserId":[NUserModel shareInstance].userInfoId?:@"",
                          @"resumeName":[NGlobalModel shareInstance].name?:@"",
                          @"resumeSex":[NGlobalModel shareInstance].gender?:@"",
                          @"resumeBirthday":[NGlobalModel shareInstance].birth?:@"",
                          @"resumeMarriage":[NGlobalModel shareInstance].marriage?:@"",
                          @"resumeHeight":[NGlobalModel shareInstance].height?:@"",
                          @"resumeBodyWeight":[NGlobalModel shareInstance].weight?:@"",
                          @"resumePlace":[NGlobalModel shareInstance].region?:@"",
                          @"resumePhone":[NGlobalModel shareInstance].phone?:@"",
                          @"resumeEmail":[NGlobalModel shareInstance].email?:@"",
                          @"resumeEducation":[NGlobalModel shareInstance].xueli?:@"",
                          @"resumeSchool":[NGlobalModel shareInstance].school?:@"",
                          @"resumeProfession":[NGlobalModel shareInstance].profession?:@"",
                          @"resumeWorkNature":[NGlobalModel shareInstance].jobProperty?:@"",
                          @"resumeWorkExperience":[NGlobalModel shareInstance].experince?:@"",
                          @"resumeIndustryIntention":[NGlobalModel shareInstance].industryWill?:@"",
                          @"resumeJobIntention":[NGlobalModel shareInstance].jobWill?:@"",
                          @"resumeProfessionalSkill":[NGlobalModel shareInstance].skill?:@"",
                          @"resumeSalary":[NGlobalModel shareInstance].salary?:@"",
                          @"resumeJobStatus":[NGlobalModel shareInstance].jobStatus?:@"",
                          @"resumeIntroduction":self.content?:@"",};
    
    ///修改请求设置 修改发送编码方式
    [NNetworkClient postRequestWithBaseUrl:kResumeUpdataUrl setParameters:dic success:^(id responseObject) {
        
        YYLog(@"%@",responseObject);
        if ([responseObject[@"code"]integerValue]==0) {
            [AFToast showText:responseObject[@"msg"]];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
        
        [NUserModel shareInstance].isDifferentRequest = NO;
    } fail:^(NSError *error) {
        
        YYLog(@"%@",error);
         [NUserModel shareInstance].isDifferentRequest = NO;
    } delegater:nil];
    
}
#pragma mark - 初始数据

//学历  (0:初中，1:高中，2:中专，3:大专，4:本科，5:硕士，6:博士)
-(NSString *)education:(NSString *)type{
    
    switch ([type integerValue]) {
        case 0:
            return @"初中";
            break;
        case 1:
            return @"高中";
            break;
        case 2:
            return @"中专";
            break;
        case 3:
            return @"大专";
            break;
        case 4:
            return @"本科";
            break;
        case 5:
            return @"硕士";
            break;
        case 6:
            return @"博士";
            break;
            
        default:
            break;
    }
    return @"";
}

//行业意向  0:不限，1:机械装备制造，2:电子信息，3:铝深加工，4:食品加工，5:生物制药，6:清洁能源，7:其他行业
-(NSString *)industryIntention:(NSString *)type{
    
    switch ([type integerValue]) {
        case 0:
            return @"不限";
            break;
        case 1:
            return @"机械装备制造";
            break;
        case 2:
            return @"电子信息";
            break;
        case 3:
            return @"铝深加工";
            break;
        case 4:
            return @"食品加工";
            break;
        case 5:
            return @"生物制药";
            break;
        case 6:
            return @"清洁能源";
            break;
        case 7:
            return @"其他行业";
            break;
            
        default:
            break;
    }
    return @"";
}

//职位意向 0:不限，1:经营管理类，2:行政/人事/后勤类，3:财务/税务/审计类，4:生产制造/工工管理类，5:市场/销售类，6:客服/计算机服务类，7:计算机/互联网类，8:科研/咨询类，9:证券/金融/投资类，10:其他类
-(NSString *)positionIntention:(NSString *)type{
    switch ([type integerValue]) {
        case 0:
            return @"不限";
            break;
        case 1:
            return @"经营管理类";
            break;
        case 2:
            return @"行政/人事/后勤类";
            break;
        case 3:
            return @"财务/税务/审计类";
            break;
        case 4:
            return @"生产制造/工工管理类";
            break;
        case 5:
            return @"市场/销售类";
            break;
        case 6:
            return @"客服/计算机服务类";
            break;
        case 7:
            return @"计算机/互联网类";
            break;
        case 8:
            return @"科研/咨询类";
            break;
        case 9:
            return @"证券/金融/投资类";
            break;
        case 10:
            return @"其他";
            break;
            
        default:
            break;
    }
    return @"";
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        
        return 50.f;
        
    }else if (indexPath.section==1){
        return 45.f;
    }
    else if (indexPath.section==2){
        ///这是是输入框
        return 155.f;
    }else{
        return 135.f;
    }
    return 0.f;
    
}
#pragma mark - datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0||section==2||section==3) {
        return 1;
    }else if (section==1){
        return self.titleArray.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    NQiuzhiModel *model = [self.dataArray lastObject];
    
    if (indexPath.section==0) {
        
        NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.name.text = @"名字";
        cell.area.hidden = YES;
        cell.date.hidden = YES;
        cell.company.hidden = YES;
        cell.salary.hidden = YES;
        cell.infoTextFd.hidden = false;
        cell.nameLeftMargin.constant = 25.f;
        return cell;
        
    }else if(indexPath.section==1){
        
        NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.nameLeftMargin.constant = 25.f;
        cell.area.hidden = YES;
        cell.date.hidden = YES;
        cell.company.hidden = YES;
        cell.salary.hidden = YES;
        cell.infoTextFd.hidden = false;
        cell.name.text = self.titleArray[indexPath.row];
        //
        cell.infoTextFd.text = self.infoArray[indexPath.row];
        return cell;
        
    }else if (indexPath.section==2){
        
        NMiaoshuCell *cell = [tableView dequeueReusableCellWithIdentifier:miaoshuCell forIndexPath:indexPath];
        cell.nameLabel.text = @"自我介绍";
        cell.describeTextView.hidden = false;
        cell.describeTextView.delegate = self;
        cell.describeTextView.tag = 666;
        cell.telTextFd.hidden = YES;//660
        cell.emailTextFd.hidden = YES;//661
//        self.selfIntroMsg = model.resumeIntroduction;
//        cell.detailLable.text = self.selfInfo;
        if (self.selfInfo.length>1) {
            cell.describeTextView.placeholder = @"";
        }else{
            cell.describeTextView.placeholder = @"请输入自我介绍";
        }
        cell.describeTextView.text = self.selfInfo;
        return cell;
        
    }
    else{
        
        NMiaoshuCell *cell = [tableView dequeueReusableCellWithIdentifier:miaoshuCell forIndexPath:indexPath];
        cell.nameLabel.text = @"联系方式";
        cell.contactLabel.hidden = false;
        cell.emailLabel.hidden = false;
        cell.dianziyoujianLabel.hidden = false;
        cell.lianxishoujiLabel.hidden = false;
        cell.detailLable.hidden = YES;
        cell.telTextFd.hidden = false;//660
        cell.emailTextFd.hidden = false;//661
        cell.describeTextView.hidden = YES;
        cell.telTextFd.text = self.tele;
        cell.emailTextFd.text = self.email;
        return cell;
    }
    
    return nil;
}

#pragma mark - 动态行高
///直接返回行高 比返回size那个少了一个步骤  推荐使用这个方法
- (CGFloat)getCellHeight:(NSString *)str withWidth:(CGFloat)width{
    CGSize size = CGSizeMake(width,MAXFLOAT); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName: kFont13};//给一个字体大小
    CGSize labelsize = [str boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine| NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    return ceil(labelsize.height);
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}


#pragma mark - textField  delegate

- (void)textViewDidEndEditing:(UITextView *)textView{
    if (textView.tag==666) {
        self.content = textView.text;
    }
}

@end
